package com.cc.persistent.controller;

import com.cc.persistent.model.Book;
import com.cc.persistent.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

//@RestController
@RequestMapping("/jdbc")
public class Bookcontroller {

    @Autowired
    BookService bookService;

    @GetMapping("/bookOps")
    public void bookOps() {
        Book bl = new Book();
        bl.setName("西厢记");
        bl.setAuthor("王实甫");
        int i = bookService.addBook(bl);
        System.out.println("addBook>>>" + i);
        Book b2 = new Book();
        b2.setId(1);
        b2.setName("朝花夕拾");
        b2.setAuthor("鲁迅");
        int updateBook = bookService.updateBook(b2);
        System.out.println("updateBook>>>" + updateBook);
        Book b3 = bookService.getBookById(1);
        System.out.println("getBookById>>>" + b3);
        int delete = bookService.deleteBookById(2);
        System.out.println("deleteBookById>>>" + delete);
        List<Book> allBooks = bookService.getAllBooks();
        System.out.println("getAHBooks>>>" + allBooks);
    }
}  